<?php
!function_exists('adminmsg') && die('Forbidden');
$tag = new Tags();
$tag->doIt($action);

class Tags{
	function doIt($action){
		if(!$action){
			$this->ShowTag();
		}elseif ($action=='del'){
			$this->DelTag();
		}elseif ($action=='add'){
			$this->AddTag();
		}
	}
	
	function AddTag(){
		global $db,$tagname;
		$tagname = Char_cv($tagname);
		!$tagname && Showmsg('ext_notagname');
		$db->update("INSERT INTO cms_tags SET tagname='$tagname'");
		adminmsg('ext_tagaddok');
	}
	
	function DelTag(){
		global $tagid,$db;
		if(is_array($tagid)){
			$tagid = checkselid($tagid);
		}else{
			$tagid = intval($tagid);
		}
		$db->update("DELETE FROM cms_tags WHERE tagid IN($tagid)");
		adminmsg('operate_success');
	}
	
	function ShowTag(){
		global $db,$page,$basename;
		$rs = $db->get_one("SELECT COUNT(*) AS total FROM cms_tags");
		$total = $rs['total'];
		if(!$page or !is_numeric($page) or $page<=0) $page = 1;
		$displaynum = 30;
		$start = (intval($page)-1)*$displaynum;
		$numofpage = ceil($total/$displaynum);
		$pages = numofpage($total,$page,$numofpage,"$basename&");
		$tagdb = $db->query("SELECT * FROM cms_tags ORDER BY tagid DESC LIMIT $start,$displaynum");
		//die("SELECT * FROM cms_tags ORDER BY tagid DESC LIMIT $start,$displaynum");
		require PrintEot('header');
		require PrintEot('tags');
		adminbottom();
	}
}
?>